<?php
/**
 * Created by PhpStorm.
 * User: apple
 * Date: 2018/11/23
 * Time: 10:25 AM
 */

namespace app\purchase\controller;

use app\purchase\model\Goods as GoodsModel;
use app\purchase\model\GoodsAccessory;
use app\purchase\model\GoodsClientPrice;
use app\purchase\model\Goodsdescribe;


use app\purchase\model\GoodsLevel;
use app\purchase\model\GoodsLevelPrice;
use app\purchase\model\GoodsUnits;
use app\purchase\model\Unit;
use app\purchase\model\Accessory as accessoryModel;
use app\shop\model\GoodsSku as GoodsSkuModel;
use app\shop\model\Img;
use think\Db;
use think\Exception;
use think\Loader;
use think\Request;
use app\purchase\model\GoodsImg as GoodsImgModel;

class Goods extends \PurchaseController
{




    public function GoodsList(Request $request){
        $GoodsModel = new GoodsModel();

        try {
            $params = $request->get();
            $data = $GoodsModel->goodsList($params);
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }

    }

    public function allGoodsList(Request $request){
        $GoodsModel = new GoodsModel();

        try {
            $params = $request->get();
            $data = $GoodsModel->allGoodsList($params);
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }
    }

    public function OrderGoodsList(Request $request){
        $GoodsModel = new GoodsModel();

        try {
            $params = $request->get();
            $data = $GoodsModel->search($params);
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }

    }



    //展示页数据
    public function GoodsInfo(Request $request){
        $GoodsModel = new GoodsModel();
        try {
            $params = $request->get();
            $data = $GoodsModel->info($params);
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }
    }
    //通过客户id 获取商品价格
    //client_id:客户id
    //goods_id :商品id
    //
    public function clientGoodsPrice($client_id,$goods_id){
       //获取客户等级
       $ClientModel = new \app\shop\model\Client();
       //        $ClientModel->alias('')->join('sh_client_level')
//        $ClientLevelModel->where()
    }

    //布尔值转化数字
    public function boolFormatInt($bool){
        return $bool == 'true' ? 1 : 0;
    }

    //数字转化布尔值
    public function intFormatBool($int){
        return $int ? true : false;
    }

    //翻译单位
    public function getUnitTrans($unit){
        if(empty($unit)) return '';
        $unitModel = new Unit();
        return $unitModel->where('unit_id',$unit)->value('unit_name');
    }
    public function text(){
       $Goods = new GoodsModel();
        $data = $Goods->specificationUnits(160,6);
        $this->successTerminate($data);
    }
}